package com.ht.medicaltreatment.activity

import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.gym.baselib.base.BaseActivity
import com.ht.medicaltreatment.R
import com.ht.medicaltreatment.adapter.CentrifugeRecordDetailAdapter
import com.ht.medicaltreatment.adapter.CentrifugeRecordOverTimeDetailAdapter
import com.ht.medicaltreatment.viewmodel.CentrifugeOrderDetailViewModel
import com.xgst.lib.utils.showToast
import kotlinx.android.synthetic.main.activity_centrifuge_record_detail_layout.*

class CentrifugeRecordDetailActivity : BaseActivity() {
    override fun getLayoutId() = R.layout.activity_centrifuge_record_detail_layout

    private val model by viewModels<CentrifugeOrderDetailViewModel>()
    private val normalAdapter = CentrifugeRecordDetailAdapter()
    private val overTimeAdapter = CentrifugeRecordOverTimeDetailAdapter()
    private var id = 0

    override fun init() {
        setTitle("样本离心详情")
        id = intent.getIntExtra("orderIdOrValue", -1)
        val orderName = intent.getStringExtra("orderName")
        val startTime = intent.getStringExtra("startTime")
        val remark = intent.getStringExtra("remark")
        val projectId = intent.getStringExtra("projectId") ?: ""

        tvOrderName.text = orderName
        tvStartTime.text = startTime
        tvRemark.text = remark

        recyclerView.layoutManager = LinearLayoutManager(this)
        showProgress()
        if (startTime == "NA") {
            recyclerView.adapter = overTimeAdapter
            model.overTimeSample(projectId, "$id", {
                dismissProgress()
                overTimeAdapter.setNewInstance(it)
            }, {
                dismissProgress()
                showToast(it)
            })
        } else {
            recyclerView.adapter = normalAdapter
            model.getData("$id", {
                dismissProgress()
                normalAdapter.setNewInstance(it)
                tvSampleCount.text = "${it.size}"
            }, {
                dismissProgress()
                showToast(it)
            })
        }
    }

}
